package com.turnengine.client.common.errorcode;

import com.javabi.command.errorcode.IErrorCode;
import com.javabi.command.errorcode.data.IErrorCodeSerializer;
import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import com.turnengine.client.global.admin.enums.AdminErrorCode;
import com.turnengine.client.global.announcement.enums.AnnouncementErrorCode;
import com.turnengine.client.global.game.enums.GameErrorCode;
import com.turnengine.client.global.user.enums.UserErrorCode;
import com.turnengine.client.local.alliance.enums.AllianceErrorCode;
import com.turnengine.client.local.faction.enums.FactionErrorCode;
import com.turnengine.client.local.group.enums.GroupErrorCode;
import com.turnengine.client.local.location.enums.LocationErrorCode;
import com.turnengine.client.local.mobile.enums.MobileErrorCode;
import com.turnengine.client.local.player.enums.PlayerErrorCode;
import com.turnengine.client.local.turn.enums.TurnErrorCode;
import com.turnengine.client.local.unit.enums.UnitErrorCode;
import java.io.IOException;

/**
 * The Error Code Serializer.
 */
public class ErrorCodeSerializer implements IErrorCodeSerializer {

	public IErrorCode readObject(IDataReader reader) throws IOException {
		short id = reader.readPositiveShort();
		switch (id) {
			case 101: return AnnouncementErrorCode.ANNOUNCEMENT_EXISTS;
			case 102: return AnnouncementErrorCode.ANNOUNCEMENT_NOT_EXISTS;
			case 301: return GameErrorCode.GAME_EXISTS;
			case 302: return GameErrorCode.GAME_NOT_EXISTS;
			case 303: return GameErrorCode.GAME_VERSION_EXISTS;
			case 304: return GameErrorCode.GAME_VERSION_NOT_EXISTS;
			case 305: return GameErrorCode.GAME_INSTANCE_EXISTS;
			case 306: return GameErrorCode.GAME_INSTANCE_NOT_EXISTS;
			case 307: return GameErrorCode.GAME_HOST_EXISTS;
			case 308: return GameErrorCode.GAME_HOST_NOT_EXISTS;
			case 501: return UserErrorCode.USER_EXISTS;
			case 502: return UserErrorCode.USER_NAME_EXISTS;
			case 503: return UserErrorCode.USER_NAME_NOT_EXISTS;
			case 504: return UserErrorCode.USER_EMAIL_EXISTS;
			case 505: return UserErrorCode.USER_NOT_EXISTS;
			case 506: return UserErrorCode.USER_NOT_VERIFIED;
			case 507: return UserErrorCode.USER_INCORRECT_VERIFICATION_CODE;
			case 508: return UserErrorCode.USER_NOT_LOGGED_IN;
			case 509: return UserErrorCode.USER_NOT_SIGNED_UP;
			case 510: return UserErrorCode.USER_LOGIN_FAILED;
			case 511: return UserErrorCode.USER_LOGIN_EXPIRED;
			case 512: return UserErrorCode.USER_LOGIN_BLOCKED;
			case 513: return UserErrorCode.USER_INCORRECT_PASSWORD;
			case 514: return UserErrorCode.USER_NOT_AUTHORISED;
			case 515: return UserErrorCode.USER_LOGIN_INVALID;
			case 601: return AdminErrorCode.INTERNAL_SERVER_ERROR;
			case 1101: return AllianceErrorCode.ALLIANCE_EXISTS;
			case 1102: return AllianceErrorCode.ALLIANCE_NOT_EXISTS;
			case 1103: return AllianceErrorCode.ALLIANCE_LEADER;
			case 1104: return AllianceErrorCode.ALLIANCE_NOT_LEADER;
			case 1105: return AllianceErrorCode.ALLIANCE_MEMBER;
			case 1106: return AllianceErrorCode.ALLIANCE_NOT_MEMBER;
			case 1107: return AllianceErrorCode.ALLIANCE_FULL;
			case 1108: return AllianceErrorCode.ALLIANCE_NOT_FULL;
			case 1109: return AllianceErrorCode.ALLIANCE_EMPTY;
			case 1110: return AllianceErrorCode.ALLIANCE_NOT_EMPTY;
			case 1111: return AllianceErrorCode.ALLIANCE_INVITE_LIMIT_REACHED;
			case 1112: return AllianceErrorCode.ALLIANCE_NOT_PRIVILEGED;
			case 1113: return AllianceErrorCode.ALLIANCE_AVATAR_NOT_EXISTS;
			case 1114: return AllianceErrorCode.ALLIANCE_MEMBER_LEAVING;
			case 1301: return FactionErrorCode.FACTION_EXISTS;
			case 1302: return FactionErrorCode.FACTION_NOT_EXISTS;
			case 1303: return FactionErrorCode.FACTION_PLAYER_LIMIT_REACHED;
			case 1304: return FactionErrorCode.FACTION_NOT_MEMBER;
			case 1401: return GroupErrorCode.GROUP_EXISTS;
			case 1402: return GroupErrorCode.GROUP_NOT_EXISTS;
			case 1501: return PlayerErrorCode.PLAYER_EXISTS;
			case 1502: return PlayerErrorCode.PLAYER_NOT_EXISTS;
			case 1503: return PlayerErrorCode.PLAYER_NAME_EXISTS;
			case 1504: return PlayerErrorCode.PLAYER_AVATAR_EXISTS;
			case 1505: return PlayerErrorCode.PLAYER_AVATAR_NOT_EXISTS;
			case 1506: return PlayerErrorCode.PLAYER_LIMIT_REACHED;
			case 1507: return PlayerErrorCode.PLAYER_ACTION_QUEUE_LIMIT_REACHED;
			case 1508: return PlayerErrorCode.PLAYER_SIGNUPS_NOT_ENABLED;
			case 1509: return PlayerErrorCode.PLAYER_NOT_LOGGED_IN;
			case 1510: return PlayerErrorCode.PLAYER_NOT_SIGNED_UP;
			case 1511: return PlayerErrorCode.PLAYER_ALREADY_SIGNED_UP;
			case 1801: return TurnErrorCode.TURN_UPDATING;
			case 1901: return UnitErrorCode.UNIT_EXISTS;
			case 1902: return UnitErrorCode.UNIT_NOT_EXISTS;
			case 2001: return LocationErrorCode.LOCATION_EXISTS;
			case 2002: return LocationErrorCode.LOCATION_NOT_EXISTS;
			case 2003: return LocationErrorCode.LOCATION_OWNED;
			case 2004: return LocationErrorCode.LOCATION_NOT_OWNED;
			case 2005: return LocationErrorCode.LOCATION_NOT_SIGNUP;
			case 2006: return LocationErrorCode.LOCATION_SIGNUP_EXISTS;
			case 2007: return LocationErrorCode.LOCATIONS_GENERATED;
			case 2008: return LocationErrorCode.NO_SIGNUP_LOCATIONS_AVAILABLE;
			case 2401: return MobileErrorCode.MOBILE_EXISTS;
			case 2402: return MobileErrorCode.MOBILE_NOT_EXISTS;
			case 2403: return MobileErrorCode.MOBILE_MOVING;
			case 2404: return MobileErrorCode.MOBILE_NOT_MOVING;
			case 2405: return MobileErrorCode.MOBILE_DESTINATION_INVALID;
			case 2406: return MobileErrorCode.MOBILE_OWNED;
			case 2407: return MobileErrorCode.MOBILE_NOT_OWNED;
		}
		throw new IllegalArgumentException("id=" + id);
	}

	public void writeObject(IDataWriter writer, IErrorCode code) throws IOException {
		if (code.equals(AnnouncementErrorCode.ANNOUNCEMENT_EXISTS)) {
			writer.writePositiveShort((short) 101);
			return;
		}
		if (code.equals(AnnouncementErrorCode.ANNOUNCEMENT_NOT_EXISTS)) {
			writer.writePositiveShort((short) 102);
			return;
		}
		if (code.equals(GameErrorCode.GAME_EXISTS)) {
			writer.writePositiveShort((short) 301);
			return;
		}
		if (code.equals(GameErrorCode.GAME_NOT_EXISTS)) {
			writer.writePositiveShort((short) 302);
			return;
		}
		if (code.equals(GameErrorCode.GAME_VERSION_EXISTS)) {
			writer.writePositiveShort((short) 303);
			return;
		}
		if (code.equals(GameErrorCode.GAME_VERSION_NOT_EXISTS)) {
			writer.writePositiveShort((short) 304);
			return;
		}
		if (code.equals(GameErrorCode.GAME_INSTANCE_EXISTS)) {
			writer.writePositiveShort((short) 305);
			return;
		}
		if (code.equals(GameErrorCode.GAME_INSTANCE_NOT_EXISTS)) {
			writer.writePositiveShort((short) 306);
			return;
		}
		if (code.equals(GameErrorCode.GAME_HOST_EXISTS)) {
			writer.writePositiveShort((short) 307);
			return;
		}
		if (code.equals(GameErrorCode.GAME_HOST_NOT_EXISTS)) {
			writer.writePositiveShort((short) 308);
			return;
		}
		if (code.equals(UserErrorCode.USER_EXISTS)) {
			writer.writePositiveShort((short) 501);
			return;
		}
		if (code.equals(UserErrorCode.USER_NAME_EXISTS)) {
			writer.writePositiveShort((short) 502);
			return;
		}
		if (code.equals(UserErrorCode.USER_NAME_NOT_EXISTS)) {
			writer.writePositiveShort((short) 503);
			return;
		}
		if (code.equals(UserErrorCode.USER_EMAIL_EXISTS)) {
			writer.writePositiveShort((short) 504);
			return;
		}
		if (code.equals(UserErrorCode.USER_NOT_EXISTS)) {
			writer.writePositiveShort((short) 505);
			return;
		}
		if (code.equals(UserErrorCode.USER_NOT_VERIFIED)) {
			writer.writePositiveShort((short) 506);
			return;
		}
		if (code.equals(UserErrorCode.USER_INCORRECT_VERIFICATION_CODE)) {
			writer.writePositiveShort((short) 507);
			return;
		}
		if (code.equals(UserErrorCode.USER_NOT_LOGGED_IN)) {
			writer.writePositiveShort((short) 508);
			return;
		}
		if (code.equals(UserErrorCode.USER_NOT_SIGNED_UP)) {
			writer.writePositiveShort((short) 509);
			return;
		}
		if (code.equals(UserErrorCode.USER_LOGIN_FAILED)) {
			writer.writePositiveShort((short) 510);
			return;
		}
		if (code.equals(UserErrorCode.USER_LOGIN_EXPIRED)) {
			writer.writePositiveShort((short) 511);
			return;
		}
		if (code.equals(UserErrorCode.USER_LOGIN_BLOCKED)) {
			writer.writePositiveShort((short) 512);
			return;
		}
		if (code.equals(UserErrorCode.USER_INCORRECT_PASSWORD)) {
			writer.writePositiveShort((short) 513);
			return;
		}
		if (code.equals(UserErrorCode.USER_NOT_AUTHORISED)) {
			writer.writePositiveShort((short) 514);
			return;
		}
		if (code.equals(UserErrorCode.USER_LOGIN_INVALID)) {
			writer.writePositiveShort((short) 515);
			return;
		}
		if (code.equals(AdminErrorCode.INTERNAL_SERVER_ERROR)) {
			writer.writePositiveShort((short) 601);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_EXISTS)) {
			writer.writePositiveShort((short) 1101);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1102);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_LEADER)) {
			writer.writePositiveShort((short) 1103);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_LEADER)) {
			writer.writePositiveShort((short) 1104);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_MEMBER)) {
			writer.writePositiveShort((short) 1105);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_MEMBER)) {
			writer.writePositiveShort((short) 1106);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_FULL)) {
			writer.writePositiveShort((short) 1107);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_FULL)) {
			writer.writePositiveShort((short) 1108);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_EMPTY)) {
			writer.writePositiveShort((short) 1109);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_EMPTY)) {
			writer.writePositiveShort((short) 1110);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_INVITE_LIMIT_REACHED)) {
			writer.writePositiveShort((short) 1111);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_NOT_PRIVILEGED)) {
			writer.writePositiveShort((short) 1112);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_AVATAR_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1113);
			return;
		}
		if (code.equals(AllianceErrorCode.ALLIANCE_MEMBER_LEAVING)) {
			writer.writePositiveShort((short) 1114);
			return;
		}
		if (code.equals(FactionErrorCode.FACTION_EXISTS)) {
			writer.writePositiveShort((short) 1301);
			return;
		}
		if (code.equals(FactionErrorCode.FACTION_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1302);
			return;
		}
		if (code.equals(FactionErrorCode.FACTION_PLAYER_LIMIT_REACHED)) {
			writer.writePositiveShort((short) 1303);
			return;
		}
		if (code.equals(FactionErrorCode.FACTION_NOT_MEMBER)) {
			writer.writePositiveShort((short) 1304);
			return;
		}
		if (code.equals(GroupErrorCode.GROUP_EXISTS)) {
			writer.writePositiveShort((short) 1401);
			return;
		}
		if (code.equals(GroupErrorCode.GROUP_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1402);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_EXISTS)) {
			writer.writePositiveShort((short) 1501);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1502);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_NAME_EXISTS)) {
			writer.writePositiveShort((short) 1503);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_AVATAR_EXISTS)) {
			writer.writePositiveShort((short) 1504);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_AVATAR_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1505);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_LIMIT_REACHED)) {
			writer.writePositiveShort((short) 1506);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_ACTION_QUEUE_LIMIT_REACHED)) {
			writer.writePositiveShort((short) 1507);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_SIGNUPS_NOT_ENABLED)) {
			writer.writePositiveShort((short) 1508);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_NOT_LOGGED_IN)) {
			writer.writePositiveShort((short) 1509);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_NOT_SIGNED_UP)) {
			writer.writePositiveShort((short) 1510);
			return;
		}
		if (code.equals(PlayerErrorCode.PLAYER_ALREADY_SIGNED_UP)) {
			writer.writePositiveShort((short) 1511);
			return;
		}
		if (code.equals(TurnErrorCode.TURN_UPDATING)) {
			writer.writePositiveShort((short) 1801);
			return;
		}
		if (code.equals(UnitErrorCode.UNIT_EXISTS)) {
			writer.writePositiveShort((short) 1901);
			return;
		}
		if (code.equals(UnitErrorCode.UNIT_NOT_EXISTS)) {
			writer.writePositiveShort((short) 1902);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_EXISTS)) {
			writer.writePositiveShort((short) 2001);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_NOT_EXISTS)) {
			writer.writePositiveShort((short) 2002);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_OWNED)) {
			writer.writePositiveShort((short) 2003);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_NOT_OWNED)) {
			writer.writePositiveShort((short) 2004);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_NOT_SIGNUP)) {
			writer.writePositiveShort((short) 2005);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATION_SIGNUP_EXISTS)) {
			writer.writePositiveShort((short) 2006);
			return;
		}
		if (code.equals(LocationErrorCode.LOCATIONS_GENERATED)) {
			writer.writePositiveShort((short) 2007);
			return;
		}
		if (code.equals(LocationErrorCode.NO_SIGNUP_LOCATIONS_AVAILABLE)) {
			writer.writePositiveShort((short) 2008);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_EXISTS)) {
			writer.writePositiveShort((short) 2401);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_NOT_EXISTS)) {
			writer.writePositiveShort((short) 2402);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_MOVING)) {
			writer.writePositiveShort((short) 2403);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_NOT_MOVING)) {
			writer.writePositiveShort((short) 2404);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_DESTINATION_INVALID)) {
			writer.writePositiveShort((short) 2405);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_OWNED)) {
			writer.writePositiveShort((short) 2406);
			return;
		}
		if (code.equals(MobileErrorCode.MOBILE_NOT_OWNED)) {
			writer.writePositiveShort((short) 2407);
			return;
		}
		throw new IllegalArgumentException("code: " + code);
	}
}
